Hello and welcome back to the costs Sunday.
Last two sessions we learned already about the data types integers and floats.
And in this session we want to repeat and deepen our understanding of those two data types.
So first of all we assign variables to let's say five.
So we assign the arrival eight to five and we assign B to the Internet two.
And we check the data types of A and B so I would expect that A and B are integers.
That's true.
Here you can see Integer Integer and what we already learned.
I mean integer floats.
That's both them are ordinary numbers where we can apply a mathematical operations like addition so
we can add a plus b we can add B plus a.
So no surprise we get seven and both uh and both operations that we can subtract.
So A minus B plus three.
We can also create negative numbers B minus a gives us minus three.
And also we can multiply two integers and get 10.
And uh what we also already learned is that by dividing into Test B.
Yeah.
We get on and float object.
So if we uh divide a divided by B So five divided by two we get 2.5 and we assign 2.5 to the right of
C..
So C is 2.5.
And uh the data type of C is a float object and that's actually the difference between antigen and then
float integers a number that can be written without fractional component.
So 5 or 2 both don't have any any decimal.
And in contrast a float object has a decimal so if you can see here C has a that one decimal point five
at this point I want to highlight the different data types have different functionality and all the
data types have so-called built in methods or attributes.
So actually at this point I don't want to go into detail of object oriented programming but I want to
show you the practical use of the so-called methods and attributes.
So let's have a look at um the float the float object see and we can call the method as integer array
so by pressing C dot and then s integer ratio and if we execute the cell here it can see that C as an
integer Horatio is five divided pi 2.
So this is called a method because Python internally calculates something based on our object.
Um yeah.
2.5.
So it returns the integer ratio of 5 will divided by 2.
And we can also browse or search for built in methods or attributes by just uh uh let's take uh the
float C dot and then press tab and then we can see what Python offers us.
So we have a method as integral ratio and uh with quite a few methods and then attributes here.
So for instance we can call the method as integer and executed.
Okay so now python is checking if C as a float as an integer and obviously it's not an integer so it
returns a false so now if you go to our variable B is the B stands for 4 2 so it's B is an integer and
then we can call the attribute denominator.
And numerator Casale actually that squared.
Yeah.
I mean that's not too much too much more information here.
So two is made of the numerator.
Two divided by one.
So that's not not too much helpful actually.
And we can also check here what other methods or attributes we have by pressing the tap key bit length
conjugate.
It's not too interesting for us now.
So I think we should go on and um yeah let's let's calculate 11 divided by three and assign it to the
variety of D.
Gives us three points six six six.
And the if you call now the method as integer ratio you have to get quite quiet.
Um yeah.
It doesn't give us what we expected.
Um eleven and three because um the float a C uh by default around it.
After uh.
I don't know the tenth uh digit so now I mean doesn't have too much here.
The two numbers but nice to know actually.
And um yeah.
What we can also do we can call a function on an object like this or a function like round so we can
round our float object and let's press shift tab to.
Okay we can round a number so it s d s stands for a float and we can also determine the number of digits.
So if we take here 1 so we can round our float object here to 1 digit and we get three point seven.
So if we change it here to 2 we get three point six seven obviously with uh into the integers rounding
doesn't make really sense because we are an integer doesn't have any digits.
And what we can also do we can transform our flowed into an integer by calling the function int so INT.
And then in brackets to give them the corresponding integer to the float D.
And what Python actually does it just cuts here um all digits so that's not rounding if it's would round
so we would get four but it's just cutting here after the three and we get um the integer three
and we can also transform an integer A stands for five into a float and gives us five point zero and
there are two ways to transform an integer into a float.
So either we call the function float or um so let's check first of all the type of uh five should be
an integer.
And if you just press 5 dot 0 Python recognizes 5.0 as a float and even we don't have to press 0 so
only five point nothing gives us a float.
So Python treats as of a float and also here there are two ways to transform an integer into a string.
So either by uh setting or putting five into quotation marks or by calling the s t r function.
So by calling a c r our five will be transformed into a string.
All right so that s the same as here.
Yeah.
That's it for now at this point.
So that's not much more to say about integers and floats and.
Yeah.
In the next session we will have a deeper look into uh.
String object.
So hope you enjoyed it and uh hope to see you in the next session.
By.